package com.vodafone.mapreduce.dto.function;

import java.io.Serializable;
import java.util.List;

import com.vodafone.mapreduce.MapReduce;
import com.vodafone.mapreduce.dto.common.KeyValuePair;

/**
 * This class implements a rich DTO that contains two segments of data:
 * <ol>
 * <li>the original pair (k, v) that was provided as an input for the map function and</li>
 * <li>the output of the map function (l, v)*</li>
 * </ol>
 */
/**
 * Input for the combine function.
 *
 * @param <K>
 * @param <V>
 * @param <L>
 * @param <W>
 */
public class CombineInput<K, V, L, W> implements Serializable {

    // -------------------------------------------------------------------------------------------------------------------------------------
    // Class constants.
    // -------------------------------------------------------------------------------------------------------------------------------------

    private static final long serialVersionUID = MapReduce.SERIAL_VERSION_UID;

    // -------------------------------------------------------------------------------------------------------------------------------------
    // Instance attributes.
    // -------------------------------------------------------------------------------------------------------------------------------------

    private final K k;
    private final V v;
    private final List<KeyValuePair<L, W>> intermediate;

    // -------------------------------------------------------------------------------------------------------------------------------------
    // Instance constructors.
    // -------------------------------------------------------------------------------------------------------------------------------------

    public CombineInput(K k, V v, List<KeyValuePair<L, W>> intermediate) {
        this.k = k;
        this.v = v;
        this.intermediate = intermediate;
    }

    // -------------------------------------------------------------------------------------------------------------------------------------
    // Instance methods.
    // -------------------------------------------------------------------------------------------------------------------------------------

    public K getKey() {
        return k;
    }

    public V getValue() {
        return v;
    }

    public List<KeyValuePair<L, W>> getIntermediate() {
        return intermediate;
    }

    public String toString() {
        return "K:'" + k + "'; " + "V:'"
                + (v != null ? (v.toString().length() > 25 ? v.toString().substring(0, 25) + "..." : v.toString()) : "<null>") + "'; "
                + "intermediate:" + intermediate.toString();
    }

    // -------------------------------------------------------------------------------------------------------------------------------------

}
